﻿using System.IO;
using System.Linq;

namespace Adjunct.Framework.NuGet
{
	public static class PackageDirectory
	{
		public static SemanticVersion GetMaxInstalledVersion(string packagesDir, string packageName)
		{
			int versionStartIndex = packageName.Length + 1;
			return
				Directory.GetDirectories(packagesDir, string.Format("{0}.*", packageName))
				.Select(Path.GetFileName)
				.Select(s => s.Substring(versionStartIndex))
				.Select(s => new SemanticVersion(s))
				.Max(v => v);
		}
	}
}